<template>
  <view class="map-container">
    <AMap id="map"></AMap>
  </view>
</template>
<script>
// import { AMap } from '@dcloudio/uni-ai-amap'
export default {
  components: {
    AMap
  },
  onReady() {
    // 在页面准备好后获取当前位置并定位到地图
    this.getLocation()
  },
  methods: {
    getLocation() {
      uni.getLocation({
        type: 'gcj02',
        success: (res) => {
          const { latitude, longitude } = res
          this.initMap(latitude, longitude)
        }
      })
    },
    initMap(latitude, longitude) {
      const mapContext = uni.createMapContext('map', this)
      mapContext.moveToLocation({
        latitude,
        longitude
      })
    }
  }
}
</script>
<style>
.map-container {
  width: 100vw;
  height: 100vh;
}
</style>